<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp"%>
<title>list</title>
<script type="text/javascript" ></script>
</head>

<body>
	<div class="layui-collapse">
		<div class="layui-colla-item">
			<h2 class="layui-colla-title">部门信息-查询条件</h2>
			<div class="layui-colla-content layui-show">
				<fieldset class="layui-elem-field layui-field-title" style="margin-top: 0px; padding:0.2cm;">
                    <legend>部门信息-查询条件</legend>
					<form class="layui-form">
					   <div class="layui-form-item">
					       <label class="layui-form-label">部门编号</label>
					       <div class="layui-input-inline">
					           <input type="text" name="code" placeholder="请输入部门编号" class="layui-input"/>
					       </div>
					       <label class="layui-form-label">部门名称</label>
					       <div class="layui-input-inline">
					           <input type="text" name="name" placeholder="请输入部门名称" class="layui-input"/>
					       </div>
					       <span>
					           <input type="button" class="layui-btn layui-btn-sm" lay-submit lay-filter="search" value="查询"/>
					           <input type="reset" class="layui-btn layui-btn-sm" value="重置">
					           <input type="button" class="layui-btn layui-btn-sm" value="添加" onclick="openAdd()">
					       </span>
				        </div>
<!-- 				        <input type="hidden" name="action" value="list" /> -->
				        <input type="hidden" name="action" value="page" />
				        <input type="hidden" name="pageIndex" value="1" />
				        <input type="hidden" name="pageLimit" value="10" />
				    </form>
				 </fieldset>
		     </div>
		 </div>
    </div>
	<div class="layui-form">
		<table class="layui-table">
			<colgroup>
				<col width="10%"><col width="15%"><col width="15%">
				<col width="15%"><col width="15%"><col width="15%"><col>
			</colgroup>
			<thead>
				<tr>
					<th>序号</th> <th>编号</th>    <th>名称</th>
					<th>电话</th> <th>部门人数</th> <th>操作</th>
				</tr>
			</thead>
			<tbody id="user_tbody"></tbody>
		</table>
		<div id="pageInfoUser" style="text-align: right; padding-right: 30px"></div>
	</div>

<script type="text/javascript">
     element.render();
     formSubmit("/department","submit(search)","json",function(data){
    	 var curr = $("input[name='pageIndex']").val();
    	 var limit = $("input[name='pageLimit']").val();
    	 setPageInfo('pageInfoUser', data.count, curr, limit, function(obj,first){
    		 $("input[name='pageIndex']").val(obj.curr);
    		 $("input[name='pageLimit']").val(obj.limit);
    		 if(!first){
    			 refresh();
    		 }
    	 }); 
    	 
    	 var html = "";
    	 $.each(data.list,function(i,dom){
    		 var name = dom.name ? dom.name:"";
    		 var tel = dom.tel ? dom.tel:"";
    		 var count = dom.count ? dom.count:0;
    		 var d = {i:i+1, code:dom.code, name:name, tel:tel, count:count};
    		 html += getlaytpl("#tradd",d);
    	 })
    	 $("#user_tbody").html(html);
    	 layer.msg("查询成功");
     })
     refresh();
     function refresh(){
    	 $("input[value='查询']").click();
     }
     
     function openAdd(){
    	  openLayer("/web/page/department/add.jsp",refresh);
     }
     
     function del(code){
    	openConfirm(function(){
    		ajax('/department',{action:"del",code:code},'text', function(data){
    			if("exist" == data){
    				layer.msg("删除失败，该记录正在被使用");
    			}else if(1 == data){
    				layer.msg("删除成功", refresh);
    			}else{
    				layer.msg("删除失败");
    			}
    		})
    	}, "确认是否删除该记录？");
     }
     
     function openUpd(code){
    	 // 两种方式都要会    	 
//     	 openLayer("/web/page/department/upd.jsp?code=" + code,refresh);
    	 openLayer("/department?action=get2&code=" + code,refresh);
     }
     

</script>
<script type="text/html" id="tradd">
<tr>
    <td>{{ d.i }}</td>
    <td>{{ d.code }}</td>
    <td>{{ d.name }}</td>
    <td>{{ d.tel }}</td>
    <td>{{ d.count }}</td>
    <td>
        <a href='javascript:del("{{ d.code }}");' class='layui-btn layui-btn-sm layui-btn-danger'>
            <i class='layui-icon layui-icon-delete'></i>
        </a>&nbsp;&nbsp;
        <input type='button' class='layui-btn layui-btn-sm' value='修改'
            onclick='openUpd("{{ d.code }}")'>
    </td>
</tr>
</script>

</body>
</html>